<template>
  <el-dialog
    append-to-body
    :close-on-click-modal="false"
    :before-close="crud.cancelCU"
    :visible="crud.status.cu > 0"
    :title="crud.status.title"
    width="500px"
  >
    <el-form
      label-width="100px"
      size="small"
      ref="form"
      :model="form"
      :rules="rules"
    >
      <el-form-item label="供应商名称" prop="supplierName">
        <el-input v-model="form.supplierName"/>
      </el-form-item>
      <el-form-item label="联系电话" prop="supplierPhone">
        <el-input v-model="form.supplierPhone"/>
      </el-form-item>
      <el-form-item label="微信号" prop="supplierWechat">
        <el-input v-model="form.supplierWechat"/>
      </el-form-item>
      <el-form-item label="联系地址" prop="supplierAddress">
        <el-input v-model="form.supplierAddress"/>
      </el-form-item>
      <el-form-item label="有效标志" prop="status">
        <el-radio v-model="form.status" :label="0">正常</el-radio>
        <el-radio v-model="form.status" :label="1">无效</el-radio>
      </el-form-item>
      <el-form-item label="供应商简介" prop="supplierIntroduce">
        <el-input v-model="form.supplierIntroduce" type="textarea" :rows="4" />
      </el-form-item>
      <!-- <el-form-item label="药房" prop="pharmacyId">
        <el-input v-model="form.pharmacyId"/>
      </el-form-item> -->
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click="crud.cancelCU">取消</el-button>
      <el-button :loading="crud.procesLoading" type="primary" @click="crud.submitCU">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
import CRUD, { form } from '@crud/crud';

const defaultForm = {
  supplierIntroduce: null,
  supplierAddress: null,
  supplierWechat: null,
  supplierPhone: null,
  supplierName: null,
  pharmacyId: null,
  status: 0
}

export default {
  name: "supplierForm",
  mixins: [ form(defaultForm) ],
  props: {
    pharmacyId: {
      type: String | Number,
      required: true
    }
  },
  data() {
    return {
      rules: {
        supplierName: [
          { required: true, message: '请输入供应商名称', trigger: 'blur' }
        ],
        status: [
          { required: true, message: '请选择有效标志', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    [CRUD.HOOK.beforeToCU]() {
      this.form.pharmacyId = this.pharmacyId;
    }
  }
}
</script>